package com.CMUBiS.util;

import java.util.Date;


/**
 * This class holds the data of a bid that the user had made. We may not need all of the information so
 * we have the tradeoff between making things immutable and reading less from the DB
 * 
 * TODO: Andy: I think we should go with the 'reading as little from the DB as we can' way. I need to update
 * ALL (aarrrrrrr!!!!) of the SQL statement
 * 
 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
 * @version 0.1
 * @since 0.1
 * @date 04/05/2011
 */
public class Bid {
	// Variables to hold the user data
	private Item bidItem;
	private int id;
	private int userID;
	private int quantity;
	private float bid;
	private float maxBid;
	private Date bidDate;
	private static final boolean immutableWarning = true;
	
	/**
	 * Create a new bid object.
	 * 
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public Bid(){
		if(Bid.immutableWarning) Bid.printWarning();
	}
	
	/**
	 * Create a new bid object will all of the info included
	 * 
	 * @param quantity
	 * @param bid
	 * @param maxBid
	 * @param bidDate
	 * @param bidItem
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public Bid(int id, int userID, int quantity, float bid, float maxBid, Date bidDate, Item bidItem){
		this.id = id;
		this.userID = userID;
		this.quantity = quantity;
		this.bid = bid;
		this.maxBid = maxBid;
		this.bidDate = bidDate;
		this.bidItem = bidItem;
	}
	
	public int getUserID(){
		return this.userID;
	}
	
	/**
	 * Return the number that the user wants to buy
	 * 
	 * @return int the number of items the user is willing to buy
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public int getQuantity(){
		return this.quantity;
	}
	
	/**
	 * Set the number of items that the user is willing to buy
	 * 
	 * @param quantity
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public void setQuantity(int quantity){
		if(Bid.immutableWarning) Bid.printWarning();
		this.quantity = quantity;
	}
	
	/**
	 * Get the amount the user has currently bid for the item
	 * 
	 * @return float the amount the user bid
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public float getBid(){
		return this.bid;
	}
	
	/**
	 * Set the amoung that the user has bid for the item
	 * 
	 * @param bid
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public void setBid(float bid){
		if(Bid.immutableWarning) Bid.printWarning();
		this.bid = bid;
	}
	
	/**
	 * Get the maximum that the user is willing to bid for the item
	 * 
	 * @return float the max the user is willing to pay
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public float getMaxBid(){
		return this.maxBid;
	}
	
	/**
	 * Set the maximum amount that the user is willing to pay for the item
	 * 
	 * @param maxBid
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public void setMaxBid(float maxBid){
		if(Bid.immutableWarning) Bid.printWarning();
		this.maxBid = maxBid;
	}
	
	/**
	 * Get the date that the user placed the bid
	 * 
	 * @return Date when the user placed the bid
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public Date getBidDate(){
		return this.bidDate;
	}
	
	/**
	 * Set the date when the user placed the bid
	 * 
	 * @param bidDate
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public void setBidDate(Date bidDate){
		if(Bid.immutableWarning) Bid.printWarning();
		this.bidDate = bidDate;
	}
	
	/**
	 * Get the item that the user bid for
	 * 
	 * @return Item that the user bid for
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public Item getItem(){
		return this.bidItem;
	}
	
	/**
	 * Set the item that the user bid for
	 * 
	 * @param bidItem
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	public void setItem(Item bidItem){
		if(Bid.immutableWarning) Bid.printWarning();
		this.bidItem = bidItem;
	}
	
	/**
	 * Print the warning about this object being immutable
	 * This can be turned off with immutableWarning=false;
	 * 
	 * @author Andy (andrewtu@cmu.edu, turner.andy@gmail.com)
	 */
	private static void printWarning(){
		System.out.println("Bid (printWarning): Please consider using this class as immutable. The 'set' methods may not be doing what you think. They only set values for this Java object and does not set them in the database. Talk to me if you want to change the design - Andy");
	}
}
